package edu.pku.sei.transformation.editor.views.figures;

import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;

import edu.pku.sei.transformation.editor.views.icons.IconsProvider;

public class ConstraintFigure extends BentCornerFigure {
	private TextArea text = new TextArea();
	private Label head = new Label("<<Constraint>>");
	private final static int HEAD_HEIGHT = 10;
	public final static int CHECK_SUCCESS = 0;
	public final static int CHECK_FAILED = 1;
	public final static int NONE = -1;

	public ConstraintFigure() {
		this.setLayoutManager(new XYLayout());
		head.setFont(FontConstant.STEREO_TYPE_LABEL);
		this.add(head);
		this.add(text);
		text.setBorder(new MarginBorder(5));
	}

	public void setText(String s) {
		text.setText(s);
	}

	public void setHead(String s) {
		head.setText(s);
	}

	@Override
	public void setBounds(Rectangle rect) {
		super.setBounds(rect);

		head.setLocation(rect.getLocation());
		head.setSize(rect.width, HEAD_HEIGHT);

		text.setLocation(new Point(rect.x, rect.y + HEAD_HEIGHT));
		text.setSize(rect.width, rect.height - HEAD_HEIGHT);
	}
	
	private void setHeadIcon(int type) {
		if (type == CHECK_SUCCESS) {
			head.setIcon(IconsProvider.getImage(IconsProvider.STATE_SUCCESS_ICO));
		} else if (type == CHECK_FAILED) {
			head.setIcon(IconsProvider.getImage(IconsProvider.STATE_FAIL_ICO));
		} else {
			head.setIcon(null);
		}
	}
	
	public void setSuccessIcon() {
		setHeadIcon(CHECK_SUCCESS);
	}
	
	public void setFailedIcon() {
		setHeadIcon(CHECK_FAILED);
	}
	
	public void clearIcon() {
		setHeadIcon(NONE);
	}
	
	
}
